<?php
namespace app\web\model;

use think\facade\Request;
/**
 * @package app\basic\model
 */
class Config extends Base 
{

    protected function setOrderCancelTimeAttr($v){
        return 60*$v;
    }
    protected function setUnconfirmedTimesAttr($v){
        return 60*$v;
    }
    protected function setOrderHourAttr($v){
        return 3600*$v;
    }
    protected function setOrderCompleteTimeAttr($v){
        return 3600*$v;
    }
    protected function setOfflineDayAttr($v){
        return 86400*$v;
    }
    protected function setServiceStartBeforeAttr($v){
        return 60*$v;
    }
    public static function getConfig($key=''){
        if($key) return self::where('id',1)->value($key);
        return self::where('id',1)->find();
    }
    public static function getWechatConfig($appkey = null,$client = 0)
    {
        $client = $client > 0 ? $client : Request::instance()->header('client',0);
        $appkey = $appkey ? $appkey : Request::instance()->header('appkey',0);
        $config = config('wechat.');
        if($client == 1){   //h5
            $config['app_id'] = $config['app'][3]['app_id'];
            $config['secret'] = $config['app'][3]['secret'];
        }else{   //小程序
            $config['app_id'] = $config['app'][$appkey]['app_id'];
            $config['miniapp_id'] = $config['app'][$appkey]['miniapp_id'];
            $config['secret'] = $config['app'][$appkey]['secret'];
        }
        unset($config['app']);
        return $config;
    }
    public static function getAppKey()
    {
        return Request::instance()->header('appkey',0);
    }
    public static function getClient(){
        return Request::instance()->header('client',0);
    }
}
